
import React from 'react'
import { Button, Select, Space, DatePicker, message } from "antd"
import { inject, observer } from "mobx-react";
import { withRouter } from 'react-router-dom';



const { Option } = Select;
const { RangePicker } = DatePicker;

function handleChange(value) {
    console.log(`selected ${value}`);
}


@inject('updateMiaoSha')

@observer

class MiaoShainsert extends React.Component {


    constructor() {
        super()
        this.state = {
            myFrom: {}
        }
    }


    componentWillMount() {
        this.props.updateMiaoSha.updateGoods()
    }

    bangDing = (name) => {
        return (e) => this.props.updateMiaoSha.insertStart(name, e)
    }

    render() {
        let { myFrom, goodsList } = this.props.updateMiaoSha

        let methodTab = () => {
            this.props.updateMiaoSha.insertData().then(data => {
                data === 200 ? this.props.history.push('/Home/cuXiao/MiaoSha/XianShiMiaoSha') : message.warning('服务器开小差,请稍后再试')
            })
        }
        let temp
        console.log(myFrom.isUpdate)
        if (myFrom.isUpdate) {
            temp = <div className="itemContentRow">
                <span>商品名称：</span>
                <span>{myFrom.goodsName}</span>
            </div>
        } else {
            temp = 
            <div className="itemContentRow">
                <span>商品名称:</span>
                <Select placeholder="请选择" direction={myFrom.goodsId} style={{ width: 200 }} onChange={this.bangDing('goodsId')}>
                    {goodsList.map(item => {
                        return <Option key={item.goodsId} value={item.goodsId}>{item.goodsName}</Option>
                    })}
                </Select>
                {/* <input type="text" value={myFrom.goodsName} onChange={bangDing('goodsName')} placeholder="此劵可抵的金额" /> */}
            </div>
        }


        return (
            <div className="miaoSha">
                <h1 >新增秒杀</h1>
                <div className="itemContentRow">
                    <span>商品关键字:</span>
                    <input type="text" value={myFrom.keyWord} onChange={this.bangDing('keyWord')} placeholder="关键字" />
                    <Button type="primary">搜索</Button>
                </div>

                {temp}

                <div className="itemContentRow">
                    <span>活动日期:</span>
                    <Space direction={myFrom.huoDongDate} size={12}>
                        <RangePicker onChange={this.bangDing('huoDongDate')} size='middle' />
                    </Space>
                </div>

                <div className="itemContentRow">
                    <span>团购人数:</span>
                    <input type="text" value={myFrom.skBuskcount} onChange={this.bangDing('skBuskcount')} placeholder="此劵可抵的金额" />
                </div>

                <div className="itemContentRow">
                    <span>秒杀价格:</span>
                    <input type="text" value={myFrom.skPrice} onChange={this.bangDing('skPrice')} placeholder="此劵可抵的金额" />
                </div>

                <div className="itemContentRow">
                    <span>秒杀库存:</span>
                    <input type="text" value={myFrom.skIt} onChange={this.bangDing('skIt')} placeholder="此劵可抵的金额" />
                </div>

                <div className="itemContentRow">
                    <span>秒杀规则:</span>
                    <input type="text" value={myFrom.skRuler} onChange={this.bangDing('skRuler')} placeholder="此劵可抵的金额" />
                </div>

                <Button type="primary" onClick={methodTab}>确定</Button>
            </div>
        )
    }
}

export default withRouter(MiaoShainsert)
